package tosp.job;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Vector;


public class JobReader {

	public static Vector<Job> fromFile(String fn) throws java.io.IOException {
		Vector<Job> ret = new Vector<Job>();
		File f=new File(fn);
		java.io.BufferedReader in=new BufferedReader(new FileReader(f));
		String line = in.readLine();
		int index = 0;
		    while (line != null) {
				if (line.length()<1 || line.startsWith("#")) continue;
				
				String a[]=line.split(":",2);
				String b[]=a[1].split("#",2);
				int jobid= Integer.parseInt(a[0]);
				String comment=b[1];
				String toolstr[]=b[0].split(",");
				int tools[]=new int[toolstr.length];
				for(int i=0;i<toolstr.length;i++) {
					tools[i]=Integer.parseInt(toolstr[i]);
				}
				SimpleJob j=new SimpleJob(jobid,tools);
				j.setComment(comment);
				j.setIndex(index++);
				ret.add(j);
		      line = in.readLine();
		    }
		in.close();
		return ret;
	}
	
	
}
